﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Business.DAL
{
	/// <summary>
	/// 数据访问类t_Business_Record_SubInfo4。
	/// </summary>
	public class t_Business_Record_SubInfo4
	{
		public t_Business_Record_SubInfo4()
		{}
		#region  成员方法

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public static void Add(Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4 model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into t_Business_Record_SubInfo4(");
			strSql.Append("RecordId,AnswerId,BargainId,FilePath,FileName,CreateCityId,CreateCityName,CreateCompanyId,CreateCompanyName,CreateDepartmentId,CreateDepartmentName,CreateUserId,CreateUserName,CreateTime)");

			strSql.Append(" values (");
			strSql.Append("@RecordId,@AnswerId,@BargainId,@FilePath,@FileName,@CreateCityId,@CreateCityName,@CreateCompanyId,@CreateCompanyName,@CreateDepartmentId,@CreateDepartmentName,@CreateUserId,@CreateUserName,@CreateTime)");
			Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
			DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
			db.AddInParameter(dbCommand, "AnswerId", DbType.Guid, model.AnswerId);
			db.AddInParameter(dbCommand, "BargainId", DbType.Guid, model.BargainId);
			db.AddInParameter(dbCommand, "FilePath", DbType.AnsiString, model.FilePath);
			db.AddInParameter(dbCommand, "FileName", DbType.AnsiString, model.FileName);
			db.AddInParameter(dbCommand, "CreateCityId", DbType.Guid, model.CreateCityId);
			db.AddInParameter(dbCommand, "CreateCityName", DbType.AnsiString, model.CreateCityName);
			db.AddInParameter(dbCommand, "CreateCompanyId", DbType.Guid, model.CreateCompanyId);
			db.AddInParameter(dbCommand, "CreateCompanyName", DbType.AnsiString, model.CreateCompanyName);
			db.AddInParameter(dbCommand, "CreateDepartmentId", DbType.Guid, model.CreateDepartmentId);
			db.AddInParameter(dbCommand, "CreateDepartmentName", DbType.AnsiString, model.CreateDepartmentName);
			db.AddInParameter(dbCommand, "CreateUserId", DbType.Guid, model.CreateUserId);
			db.AddInParameter(dbCommand, "CreateUserName", DbType.AnsiString, model.CreateUserName);
			db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime, model.CreateTime);
			db.ExecuteNonQuery(dbCommand);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public static void Update(Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4 model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update t_Business_Record_SubInfo4 set ");
			strSql.Append("AnswerId=@AnswerId,");
			strSql.Append("BargainId=@BargainId,");
			strSql.Append("FilePath=@FilePath,");
			strSql.Append("FileName=@FileName,");
			strSql.Append("CreateCityId=@CreateCityId,");
			strSql.Append("CreateCityName=@CreateCityName,");
			strSql.Append("CreateCompanyId=@CreateCompanyId,");
			strSql.Append("CreateCompanyName=@CreateCompanyName,");
			strSql.Append("CreateDepartmentId=@CreateDepartmentId,");
			strSql.Append("CreateDepartmentName=@CreateDepartmentName,");
			strSql.Append("CreateUserId=@CreateUserId,");
			strSql.Append("CreateUserName=@CreateUserName,");
			strSql.Append("CreateTime=@CreateTime");
			strSql.Append(" where RecordId=@RecordId ");
			Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
			DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
			db.AddInParameter(dbCommand, "AnswerId", DbType.Guid, model.AnswerId);
			db.AddInParameter(dbCommand, "BargainId", DbType.Guid, model.BargainId);
			db.AddInParameter(dbCommand, "FilePath", DbType.AnsiString, model.FilePath);
			db.AddInParameter(dbCommand, "FileName", DbType.AnsiString, model.FileName);
			db.AddInParameter(dbCommand, "CreateCityId", DbType.Guid, model.CreateCityId);
			db.AddInParameter(dbCommand, "CreateCityName", DbType.AnsiString, model.CreateCityName);
			db.AddInParameter(dbCommand, "CreateCompanyId", DbType.Guid, model.CreateCompanyId);
			db.AddInParameter(dbCommand, "CreateCompanyName", DbType.AnsiString, model.CreateCompanyName);
			db.AddInParameter(dbCommand, "CreateDepartmentId", DbType.Guid, model.CreateDepartmentId);
			db.AddInParameter(dbCommand, "CreateDepartmentName", DbType.AnsiString, model.CreateDepartmentName);
			db.AddInParameter(dbCommand, "CreateUserId", DbType.Guid, model.CreateUserId);
			db.AddInParameter(dbCommand, "CreateUserName", DbType.AnsiString, model.CreateUserName);
			db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime, model.CreateTime);
			db.ExecuteNonQuery(dbCommand);

		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public static void Delete(Guid RecordId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from t_Business_Record_SubInfo4 ");
			strSql.Append(" where RecordId=@RecordId ");
			Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
			DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "RecordId", DbType.Guid,RecordId);
			db.ExecuteNonQuery(dbCommand);

		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public static Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4 GetModel(Guid RecordId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select RecordId,AnswerId,BargainId,FilePath,FileName,CreateCityId,CreateCityName,CreateCompanyId,CreateCompanyName,CreateDepartmentId,CreateDepartmentName,CreateUserId,CreateUserName,CreateTime from t_Business_Record_SubInfo4 ");
			strSql.Append(" where RecordId=@RecordId ");
			Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
			DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
			db.AddInParameter(dbCommand, "RecordId", DbType.Guid,RecordId);
			Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4 model=null;
			using (IDataReader dataReader = db.ExecuteReader(dbCommand))
			{
				if(dataReader.Read())
				{
					model=ReaderBind(dataReader);
				}
                dataReader.Close();
                dataReader.Dispose();
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public static DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select RecordId,AnswerId,BargainId,FilePath,FileName,CreateCityId,CreateCityName,CreateCompanyId,CreateCompanyName,CreateDepartmentId,CreateDepartmentName,CreateUserId,CreateUserName,CreateTime ");
			strSql.Append(" FROM t_Business_Record_SubInfo4 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
			return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public static DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
			DbCommand dbCommand = db.GetStoredProcCommand("UP_GetRecordByPage");
			db.AddInParameter(dbCommand, "tblName", DbType.AnsiString, "t_Business_Record_SubInfo4");
			db.AddInParameter(dbCommand, "fldName", DbType.AnsiString, "ID");
			db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
			db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
			db.AddInParameter(dbCommand, "IsReCount", DbType.Boolean, 0);
			db.AddInParameter(dbCommand, "OrderType", DbType.Boolean, 0);
			db.AddInParameter(dbCommand, "strWhere", DbType.AnsiString, strWhere);
			return db.ExecuteDataSet(dbCommand);
		}*/

		/// <summary>
		/// 获得数据列表（比DataSet效率高，推荐使用）
		/// </summary>
		public static List<Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4> GetListArray(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select RecordId,AnswerId,BargainId,FilePath,FileName,CreateCityId,CreateCityName,CreateCompanyId,CreateCompanyName,CreateDepartmentId,CreateDepartmentName,CreateUserId,CreateUserName,CreateTime ");
			strSql.Append(" FROM t_Business_Record_SubInfo4 ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			List<Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4> list = new List<Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
			using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
			{
				while (dataReader.Read())
				{
					list.Add(ReaderBind(dataReader));
				}
                dataReader.Close();
                dataReader.Dispose();
			}
			return list;
		}


		/// <summary>
		/// 对象实体绑定数据
		/// </summary>
		public static Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4 ReaderBind(IDataReader dataReader)
		{
			Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4 model=new Chenxin.Lib.Business.Entity.t_Business_Record_SubInfo4();
			object ojb; 
			ojb = dataReader["RecordId"];
			if(ojb != null && ojb != DBNull.Value)
			{
				model.RecordId= new Guid(ojb.ToString());
			}
			ojb = dataReader["AnswerId"];
			if(ojb != null && ojb != DBNull.Value)
			{
				model.AnswerId= new Guid(ojb.ToString());
			}
			ojb = dataReader["BargainId"];
			if(ojb != null && ojb != DBNull.Value)
			{
				model.BargainId= new Guid(ojb.ToString());
			}
			model.FilePath=dataReader["FilePath"].ToString();
			model.FileName=dataReader["FileName"].ToString();
			ojb = dataReader["CreateCityId"];
			if(ojb != null && ojb != DBNull.Value)
			{
				model.CreateCityId= new Guid(ojb.ToString());
			}
			model.CreateCityName=dataReader["CreateCityName"].ToString();
			ojb = dataReader["CreateCompanyId"];
			if(ojb != null && ojb != DBNull.Value)
			{
				model.CreateCompanyId= new Guid(ojb.ToString());
			}
			model.CreateCompanyName=dataReader["CreateCompanyName"].ToString();
			ojb = dataReader["CreateDepartmentId"];
			if(ojb != null && ojb != DBNull.Value)
			{
				model.CreateDepartmentId= new Guid(ojb.ToString());
			}
			model.CreateDepartmentName=dataReader["CreateDepartmentName"].ToString();
			ojb = dataReader["CreateUserId"];
			if(ojb != null && ojb != DBNull.Value)
			{
				model.CreateUserId= new Guid(ojb.ToString());
			}
			model.CreateUserName=dataReader["CreateUserName"].ToString();
			ojb = dataReader["CreateTime"];
			if(ojb != null && ojb != DBNull.Value)
			{
				model.CreateTime=(DateTime)ojb;
			}
			return model;
		}

		#endregion  成员方法
	}
}

